package com.enfry.common.util.excel;

import java.util.ArrayList;
import java.util.List;

import org.jdom.Element;

public class Table extends Cell {

	private static final long serialVersionUID = 2798437350332690716L;

	private List<TR> trs = new ArrayList<TR>();

	public List<TR> getTrs() {
		return trs;
	}

	public void setTrs(List<TR> trs) {
		this.trs = trs;
	}

	public int getHight() {
		return this.trs.size();
	}

	public int getWidth() {
		int maxw = 0;
		for (int i = 0; i < this.trs.size(); i++) {
			TR tr = (TR) this.trs.get(i);
			int trw = tr.getWidth();
			if (trw > maxw) {
				maxw = trw;
			}
		}
		return maxw;
	}

	public TR getTR(int index) {
		return this.trs.get(index);
	}

	public void addTR(TR tr) {
		this.trs.add(tr);
		tr.parent = this;
	}

	public static Table load(Element element) throws Exception {
		Table table = new Table();
		List subs = element.getChildren("tr");
		if ((subs != null) && (subs.size() > 0)) {
			for (int i = 0; i < subs.size(); i++) {
				table.addTR(TR.load((Element) subs.get(i)));
			}
		}
		return table;
	}

}
